package servlet;

import dao.MajorDao;
import pojo.Major;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;

@WebServlet(value = "/findMajorByIdServlet")
public class FindMajorByIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //0. 获取ID
        String id=request.getParameter("id");
        System.out.println("id:"+id);

        Major major=MajorDao.findMajorById(id);
        //2. 用session保存专业信息
        HttpSession session=request.getSession();
        session.setAttribute("major",major );
        //3. 重定向到updateMajor.jsp
        response.sendRedirect("/lab08/updateMajor.jsp");
    }
}
